<?php
include_once 'model/comment/process.php';
include_once 'module/controls.php';
include_once 'model/user/user_create.php';
$c = new controls();
$comment = new comment();
$result = $comment->FillAllQuestion();
$resultUnAccept = $comment->FillAllQuestionAccecpt();
//check user
$user = new users();
$fillByName = $user->FillOneByName($_SESSION);
$level_decode = json_decode($fillByName["level"], true);
?>
<div id="content">
    <h2 class="jquery_tab_title"><?php echo $phrase["manager_comment_questions"] ?></h2>
    <?php if ($level_decode["admin"] != "" || $level_decode["update"] != "") { ?>
        <?php if(mysql_num_rows($resultUnAccept) > 0) : ?>
            <span class="bglinkleft"><a class="link" href="<?= $url["home"] ?>/menu/commentquestionaccept">Questions <?php echo $phrase["comment_accept"] ?></a></span>
        <?php endif; ?>
            <span class="bglinkleft"><a class="link" href="<?= $url["home"] ?>/menu/comment"><?php echo $phrase["manager_comment_page"] ?></a></span>
    <?php } ?>
    <table cellpadding="0" cellspacing="0" border="0" class="display" id="example">
        <thead>
            <tr>
                <th><?php echo $phrase["comment_name"] ?></th>
                <th><?php echo $phrase["question_title"] ?></th>
                <th><?php echo $phrase["datetime"] ?></th>
                <td class="status" width="8%"></td>
            </tr>
        </thead>
        <tbody>
            <?php
            while ($rows = mysql_fetch_array($result)) {
                $date = new DateTime($rows["comment_datetime"]);
                $i++;
                ?>
                <tr class="gradeC">
                    <td><?php echo $rows["comment_name"] ?></td>
                    <td><?php echo $rows["question_title"] ?></td>
                    <td><?php echo $date->format('d/m/Y H:i:s') ?></td>
                    <?php if ($i % 2) { ?>
                        <td class="first">
                            <?php if ($level_decode["admin"] != "" || $level_decode["update"] != "") { ?>
                                <a href="<?= $url["home"] ?>/menu/commentquestionupdate/id/<?php echo $rows["comment_id"] ?>">
                                    <image src="<?= $url["home"] ?>/images/icons/edit-icon.gif"/>
                                </a>
                            <?php } ?>
                            <?php if ($level_decode["admin"] != "" || $level_decode["update"] != "" && $level_decode["delete"]) { ?>
                                | 
                            <?php } ?>
                            <?php if ($level_decode["admin"] != "" || $level_decode["delete"] != "") { ?>
                                <a href="<?= $url["home"] ?>/menu/commentdelete/id/<?php echo $rows["comment_id"] ?>" onclick="return confirm('Bạn có chắc chắn muốn xóa không.');">
                                    <image src="<?= $url["home"] ?>/images/icons/b_drop.png"/>
                                </a>
                            <?php } ?>
                        </td>
                    <?php } else { ?>
                        <td class="last">
                            <?php if ($level_decode["admin"] != "" || $level_decode["update"] != "") { ?>
                                <a href="<?= $url["home"] ?>/menu/commentquestionupdate/id/<?php echo $rows["comment_id"] ?>">
                                    <image src="<?= $url["home"] ?>/images/icons/edit-icon.gif"/>
                                </a>
                            <?php } ?>
                            <?php if ($level_decode["admin"] != "" || $level_decode["update"] != "" && $level_decode["delete"]) { ?>
                                | 
                            <?php } ?>
                            <?php if ($level_decode["admin"] != "" || $level_decode["delete"] != "") { ?>
                                <a href="<?= $url["home"] ?>/menu/commentdelete/id/<?php echo $rows["comment_id"] ?>" onclick="return confirm('Bạn có chắc chắn muốn xóa không.');">
                                    <image src="<?= $url["home"] ?>/images/icons/b_drop.png"/>
                                </a>
                            <?php } ?>
                        </td>
                    <?php } ?>
                </tr>
            <?php } ?>
        </tbody>
        <tfoot>
            <tr>
                <th colspan="4"></th>
            </tr>
        </tfoot>
    </table>
</div>
<script type="text/javascript">
    $(document).ready(function() {
        $('#example').dataTable({
            "aaSorting": [[ 2, "desc" ]],
            "sPaginationType": "full_numbers"
        });
    } );
</script>
